﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Web.Security;
using System.Runtime.InteropServices;

namespace iResume
{
    public partial class loginpage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Session.Clear();
            email.Focus();
          
        }

        protected void loginbtn_Click(object sender, EventArgs e)
        {
     
        
        }

        protected void login_Click(object sender, ImageClickEventArgs e)
        {
            Session["usertype"] = usertypeddl.SelectedValue;
            Session["username"] = email.Text;
            Session["password"] = loginpasswordtxb.Text;

            //database
            if (usertypeddl.SelectedValue == "Administrator")
            {
                string Hashedpassword = "";
                Hashedpassword = FormsAuthentication.HashPasswordForStoringInConfigFile(loginpasswordtxb.Text, "sha1");
                loginpasswordtxb.Text = Hashedpassword;
                bool result = DBManager.adminlogin(email.Text, loginpasswordtxb.Text);
                if (result == true)
                {
                    FormsAuthentication.RedirectFromLoginPage(email.Text, false);
                    Response.Redirect("LoginAdmin.aspx");

                }
                else
                {
                    signinlbl.Text =  "*Invalid username or password ";
                }

            }



            if (usertypeddl.SelectedValue == "Job Seeker")
            {
                string Hashedpassword = "";
                Hashedpassword = FormsAuthentication.HashPasswordForStoringInConfigFile(loginpasswordtxb.Text, "sha1");
                loginpasswordtxb.Text = Hashedpassword;
                bool result = DBManager.jobseekerlogin(email.Text, loginpasswordtxb.Text);

                if (result == true)
                {
                    FormsAuthentication.RedirectFromLoginPage(email.Text, false);
                    Response.Redirect("Loginjobseeker.aspx");
                   // Response.Redirect("searchRecruiter.aspx");

                }
                else
                {
                    signinlbl.Text =  "*Invalid username or password ";
                }
            }


            if (usertypeddl.SelectedValue == "Recruiter")
            {
               
                string Hashedpassword = "";
                Hashedpassword = FormsAuthentication.HashPasswordForStoringInConfigFile(loginpasswordtxb.Text, "sha1");
                loginpasswordtxb.Text = Hashedpassword;
                bool result = DBManager.recruiterlogin(email.Text, loginpasswordtxb.Text);
                
                    
                if (result == true)
                {
                    
                    FormsAuthentication.RedirectFromLoginPage(email.Text, false);
                    Response.Redirect("recruiterView.aspx");
                 //  Response.Redirect("recruiterUpdate.aspx");
                   // Response.Redirect("SearchJobseeker.aspx");


                }
                else
                {
                    signinlbl.Text =  "*Invalid username or password ";
                }

            }

        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("createJobseeker.aspx");  
        }



        protected void ImageButton5_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("createJobseeker.aspx");
        }

    
        
        
    }
}